package practice01.info;

/**
 * @author Administrator
 * @version V1.0
 * @ProjectName:IntelliJ IDEA
 * @PackageName: practice01.info
 * @ClassName: CommodityInfo
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2019/12/5 18:25
 * @Copyright 大牛版板所有
 */
public class CommodityInfo {

    private String name; // 商品名称
    private int number;  // 商品编号
    private String typeAttr; // 所属类别
    private int amount;  // 商品数量
    private double price; // 商品价格

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public String getTypeAttr() {
        return typeAttr;
    }

    public void setTypeAttr(String typeAttr) {
        this.typeAttr = typeAttr;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        if (amount>0){
            this.amount = amount;
        }
        else {
            System.out.println("商品的数量必须大于0！");
        }
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        if (price>0){
            this.price = price;
        }
        else {
            System.out.println("商品的价格必须大于0！");
        }
    }

    public CommodityInfo(String name, int number, String typeAttr, int amount, double price) {
        this.setName(name);
        this.setNumber(number);
        this.setTypeAttr(typeAttr);
        this.setAmount(amount);
        this.setPrice(price);
    }

    public void showInfo(){
        System.out.println(this.getName()+"的数量为："+this.getAmount()+"，价格为："+this.getPrice()
                +"，商品编号为："+this.getNumber()+"，属于"+this.getTypeAttr());
    }
}
